#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <QDebug>


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置value
    ui->lcdNumber->display(10);
    //初始化定时器
    timer=new QTimer(this);
    //链接信号和槽 signal slot
    connect(timer,&QTimer::timeout,this,&Widget::handle);
    //启动定时器
    timer->start(1000);

    //设置progressBar
    ui->progressBar->setMaximum(100);
    ui->progressBar->setMinimum(0);
    ui->progressBar->setValue(0);
    //初始化定时器
    timer1=new QTimer(this);
    //链接信号和槽 signal slot
    connect(timer1,&QTimer::timeout,this,&Widget::handle1);
    //启动定时器
    timer1->start(100);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle()
{
    int value=ui->lcdNumber->intValue();
    if(value<=0)
    {
        timer->stop();
        return;
    }
    ui->lcdNumber->display(value-1);

}


void Widget::handle1()
{
    int value=ui->progressBar->value();
    qDebug()<<value;
    if(value>=100)
    {
        timer1->stop();
        return;
    }
    ui->progressBar->setValue(value+1);

}
